package cn.com.ejiakanghu.core.utils;

import cn.com.ejiakanghu.core.enums.ResultCode;
import cn.com.ejiakanghu.core.vo.BaseResult;

public class RespUtil {

    /**
     * 构造成功返回对象
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> BaseResult<T> success(T data) {
        BaseResult<T> baseResult = new BaseResult<>();

        baseResult.setCode(ResultCode.SUCCESS.code());
        baseResult.setMessage(ResultCode.SUCCESS.msg());
        baseResult.setData(data);
        return baseResult;
    }

    public static <T> BaseResult<T> success() {
        BaseResult<T> baseResult = new BaseResult<>();

        baseResult.setCode(ResultCode.SUCCESS.code());
        baseResult.setMessage(ResultCode.SUCCESS.msg());
        baseResult.setData(null);
        return baseResult;
    }


    /**
     * 构造失败返回对象
     *
     * @param <T>
     * @return
     */
    public static <T> BaseResult<T> fail() {
        return fail(ResultCode.SERVER_ERROR.code(), ResultCode.SERVER_ERROR.msg());
    }
    public static <T> BaseResult<T> fail(ResultCode resultCode) {
        return fail(resultCode.code(), resultCode.msg());
    }

    public static <T> BaseResult<T> fail(int code, String msg) {
        BaseResult<T> baseResult = new BaseResult<>();
        baseResult.setSuccess(false);
        baseResult.setCode(code);
        baseResult.setMessage(msg);
        baseResult.setData(null);
        return baseResult;
    }

    public static <T> BaseResult<T> unlogin() {
        return fail(501, "请登录");
    }

     public static <T> BaseResult<T>  badArgument() {
        return fail(401, "参数不对");
    }

    public static <T> BaseResult<T>  badArgumentValue() {
        return fail(402, "参数值不对");
    }

    public static <T> BaseResult<T> getCarerId(){
        return  fail(507,"没有找到推广员");
    }


    public static <T> BaseResult<T>  serious() {
        return fail(502, "系统内部错误");
    }

    public static <T> BaseResult<T>  unsupport() {
        return fail(503, "业务不支持");
    }

    public static <T> BaseResult<T>  updatedDateExpired() {
        return fail(504, "更新数据已经失效");
    }

    public static <T> BaseResult<T>  updatedDataFailed() {
        return fail(505, "更新数据失败");
    }

    public static <T> BaseResult<T>  unauthz() {
        return fail(506, "无操作权限");
    }
}
